<?php
namespace User\Controller;

class IndexController extends \Common\Controller\UserController {

	public function index(){
		$member = D('Member');
		        if ( IS_POST ) {
            $data = $member->create();
            $map = array('uid'=>$user['uid']);
            if ($data) {
                unset($data['salt']);
                unset($data['password']);
                $result = $member->where($map)->save($data);
                if ($result) {
                    $this->success('更新成功！');
                }else{
                    $this->error("更新失败！");
                }
            }
        }
		$uid = $this->mid;
		$extend_data = $this->getTab();
		$user_info = $member->find($user['uid']);
		if ($extend_data) {
			$user_info = array_merge($user_info,$extend_data);
		}
		$user_info['username'] = $user_info['username'];

		$this->assign('user_info',$user_info);
		$data = $member->find($uid);
		$this->assign($data);
        $this->setSeo('用户中心');
		$this->display();
		
	}
	protected function getTab(){
        $user = session('user_auth');
        $group = D('MemberExtendGroup');
        $field = D('MemberExtendSetting');
        $info = D('MemberExtend');

        $info_data = D('MemberExtend')->where(array('uid'=>$user['uid']))->select();
        foreach ($info_data as $key => $value) {
            if ($value['field_type'] == 'array') {
                $value['field_data'] = json_decode($value['field_data']);
            }
            $data[$value['field_name']] = $value['field_data'];
        }

        $list = $group->where(array('status'=>'1'))->order('sort asc')->select();
        $field_list = $field->where(array('status'=>'1'))->select();
        foreach ($field_list as $key => $value) {
            $fields[$value['extend_id']][] = $value;
        }
        $this->assign('fields',$fields);
        $this->assign('_tab',$list);
        return $data;
    }

}